package com.li.config;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.li.domain.SystemAddress;
import com.li.service.SystemAddressService;
import com.li.utlis.CommonUtil;
import com.li.utlis.FilePathUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    /**
     * 保存路径，自动从yml文件中获取数据
     *   示例： E:/cell_system/
     */
    @Autowired
    private SystemAddressService systemAddressService;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        String sysPath=FilePathUtil.getSystemAddressServicePath(systemAddressService, "root");
        sysPath= FilePathUtil.pathLast(sysPath);
        /**
         * 配置资源映射
         * 意思是：如果访问的资源路径是以“/cell_system/”开头的，
         * 就映射到本机的“E:/cell_system/”这个文件夹内，去找你要的资源
         * 注意：E:/cell_system/ 后面的 “/”一定要带上
         */
        registry.addResourceHandler("/cell_system/**")
                .addResourceLocations("file:"+sysPath);
    }
}
